<?php

namespace App\Modules\Apicrzs\Services\Public;

use App\Exceptions\Exception;
use App\Modules\Apicrzs\Entities\Public\SystemDeviceModel;
use App\Modules\Apicrzs\Services\BaseServices;
use Illuminate\Support\Facades\DB;

class SystemDeviceService extends BaseServices
{

    public function __construct(SystemDeviceModel $model)
    {
        $this->model = $model;
    }
    public function create(array $params)
    {
        DB::beginTransaction();
        try{
            if ($params['brand'] != 'devtools'){
            parent::create([
                'date'=> date('Y-m-d'),
                'device_id'=>$params['deviceId'],
                'openid'=>$params['openid']??"",
                'brand'=>$params['brand'],
                'device_brand'=>$params['deviceBrand'],
                'device_model'=>$params['deviceModel'],
                'device_type'=>$params['deviceType'],
                'host_version'=>$params['hostVersion'],
                'model'=>$params['model'],
                'os_name'=>$params['osName'],
                'ip'=>get_ip(),
                'txt'=>json_encode($params),
            ]); // TODO: Change the autogenerated stub
                }
            DB::commit();
            return true;
        }catch (Exception $e){
            DB::rollBack();
            throw new Exception($e->getMessage());
        }
    }
}
